package com.sgb.kjwl.view.ui.adapter.machine;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemLeaseSearchResultAskBinding;
import com.sgb.kjwl.model.entity.LeaseSearchResultEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class LeaseSearchResultAskAdapter extends BaseRecycleAdapter<LeaseSearchResultEntity> {

    public LeaseSearchResultAskAdapter(Context context, List<LeaseSearchResultEntity> datas) {
        super(context, R.layout.item_lease_search_result_ask, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, LeaseSearchResultEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemLeaseSearchResultAskBinding binding = (ItemLeaseSearchResultAskBinding) holder.getmBinding();
        if (null != entity) {

            //状态(1:报价中;3:报价结束;4:已完成)
            if (entity.getStatus() == 1) {
                binding.ivQuoteState.setImageResource(R.mipmap.price_ing);
            } else if (entity.getStatus() == 3) {
                binding.ivQuoteState.setImageResource(R.mipmap.price_end_gray);
            } else if (entity.getStatus() == 4) {
                binding.ivQuoteState.setImageResource(R.mipmap.price_finish_fail);
            }

            double rentalPriceInt = 0;
            try {
                rentalPriceInt = Double.parseDouble(entity.getPrice());
                if (rentalPriceInt <= 0) {
                    binding.tvSalary.setText("面议");
                } else {
                    binding.tvSalary.setText(entity.getPrice() + "元/" + entity.getRentalDurationUnit());
                }
            } catch (Exception e) {
                binding.tvSalary.setText("面议");
            }

            if (!TextUtils.isEmpty(entity.getRentalDuration())) {
                if (entity.getRentalDuration().equals("-1") || entity.getRentalDuration().equals("-1.0")) {
                    binding.tvLeaseTime.setText("面议");
                } else {
                    binding.tvLeaseTime.setText(entity.getRentalDuration() + entity.getRentalDurationUnit());
                }
            }

            if (!TextUtils.isEmpty(entity.getTaskAddr())) {
                binding.tvLeaseAddr.setText(entity.getTaskAddr());
            }else{
                binding.tvLeaseAddr.setText(entity.getAddress());
            }
            try {
                binding.tvLeasePublicTime.setText(DateUtils.stampToDay(entity.getUpdatetime()));
//                tvEndTime.setText(DateUtils.stampToDate(entity.getEndTime()));
            } catch (Exception ex) {
            }

            //设置租赁数量
            if ("4".equals(entity.getType()) || "5".equals(entity.getType()) || "6".equals(entity.getType())) {//租赁类型 1机械， 2 设备，3车辆，4 房产，5土地，6工厂
                binding.tvNumLabel.setText("租赁面积");
            } else {
                binding.tvNumLabel.setText("租赁数量");
            }
            if(!TextUtils.isEmpty(entity.getNumOrArea())){
                binding.tvNum.setText(entity.getNumOrArea());
            }

        }

    }

}
